import request from '../../utils/request';
const caseExample = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    /**
     * 获取案件列表
     * @payload{
     *  title   string
     *  caseType   string
     *  pageNum  string 
     * }
     * */ 
    GET_CASE_EXAMPLE_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.get('/caseExample/list.htm', {
          params: payload
        }).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 案例管理-更新案例/删除/推荐
     * @params payload{
     *  id string 
     *  caseType string 
     *  title string
     *  content string 
     *  recommend string  是否推荐 1推荐 0不推荐
     *  state string 
     * }
     * */ 
    UPDATE_CASE_EXAMPLE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseExample/update.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 案例管理-新建案例
     * @params payload{
     *  title string
     *  caseType string 
     *  content string
     *  recommend string
     * }
    */
    ADD_CASE_EXAMPLE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseExample/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 案例管理-详情
     * @params payload{
     *  id string
     * }
    */
    GET_CASE_EXAMPLE_DETAIL({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseExample/detail.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    }

  }
}

export default caseExample